package com.kolalo.interactive;

import java.util.Scanner;
import java.util.Stack;

import com.kolalo.comm.EvalHelper;
import com.kolalo.comm.StackUtil;
import com.kolalo.entity.StringModel;

public class InteractiveHost {
	
	public static void run() {
		while (true) {
			String code =InteractiveHost.getInputStr();
			StringModel model=new StringModel(code);
			switch(model.geStringType()) {
			case CreateFunction:
				break;
			case CreateType:
				break;
			case CreateVariable:
				break;
			case SystemCommand:
				break;
			case VariableAssignment:
				EvalHelper.eval(code,true);
				break;
			case VariableExpression:
				EvalHelper.eval(code,false);
				break;
			}
		}
	}
	
	public static String getInputStr() {
		StringBuilder stringBuilder = new StringBuilder();
		Scanner in = new Scanner(System.in);
		try {
			int i = 0;
			do {
				if (i++ == 0) {
					System.out.print("> ");
				} else {
					stringBuilder.append(System.lineSeparator());
				}
				stringBuilder.append(in.nextLine());
			} while (!StackUtil.isInputEnd(stringBuilder.toString()));
		} catch (Exception e) {
			System.out.println(e.getMessage());
			e.printStackTrace();
		}
		return stringBuilder.toString();
	}
}
